import java.util.LinkedList;
import java.util.Queue;

public class num225 {
    Queue<Integer> t1 = new LinkedList<>();
    Queue<Integer> t2 = new LinkedList<>();

    public void push(int x) {
        t2.offer(x);
        while (!t1.isEmpty()){
            t2.offer(t1.poll());
        }
        Queue t3 = t1;
        t1 = t2;
        t2 = t3;
    }

    public int pop() {
        return t1.poll();
    }

    public int top() {
        return t1.peek();
    }

    public boolean empty() {
        return t1.isEmpty();
    }
}
